/*
 *  POJ1010: STAMPS
 */

/*-------- Includes --------*/
#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

/*-------- Types --------*/

/*-------- Global Variables --------*/
int deno[64];   // denomination of stamps
int numb[64];   // number of stamps
int slen;       // length of deno and numb, number of types of stamps
// result variables
bool isFound;
bool isTie;
int  nTypes;
int  nStamp;
int  highest;
int  rslt[64];

/*-------- Function Prototypes --------*/
void dfs(int ptr, int types, int stamps, int hi, int need);

/*-------- Main Function --------*/
int main(int argc, char const *argv[])
{
    while (true) {
        int var;

        slen = 0;
        while (cin >> var && var) {
            deno[slen  ] = var;
            numb[slen++] = 0;
        }

        // EOF
        if (slen == 0) break;

        // sort
        sort(numb, numb + slen);

        while (cin >> var && var) {
            isFound = false;
            isTie   = false;

            dfs(0, 0, 0, 0, var);

            if (isFound) {
                cout << var << " (" << nTypes << "):";
                if (isTie) {
                    cout << " tie";
                } else {
                    for (int i = 0; i < slen; i++) {
                        if (rslt[i] > 0) {
                            for (int j = 0; j < rslt[i]; j++)
                                cout << " " << deno[i];
                        }
                    }
                }

                cout << endl;
            } else {
                cout << var << " ---- none" << endl;
            }
        }
    }

    return 0;
}

/*-------- Functions --------*/
void dfs(int ptr, int types, int stamps, int hi, int need)
{
    // base case: reach the bottom
    if (need == 0) {
        if (isFound) {
            if (types == nTypes) {
                if (stamps == nStamp) {
                    if (hi == highest) {
                        isTie = true;
                        return;
                    } else if (hi < highest) {
                        return;
                    }
                } else if (stamps > nStamp) {
                    return;
                }
            } else if (types < nTypes) {
                return;
            }
        }

        // update result
        isFound = true;
        isTie   = false;
        nTypes  = types;
        nStamp  = stamps;
        highest = hi;

        memcpy(rslt, numb, slen * sizeof(int));

        return;
    }

    // cut off: maximum of stamps is four
    if (stamps == 4) return;

    for (int i = ptr; i < slen; i++) {
        if (deno[i] > need) break;

        numb[i]++;

        if (numb[i] == 1) dfs(i, types + 1, stamps + 1, deno[i], need - deno[i]);
        else              dfs(i, types,     stamps + 1, deno[i], need - deno[i]);

        // revert for backtracking
        numb[i]--;
    }
}
